  package com.example.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import com.example.entity.Netfollows;
import com.example.entity.Students;
import com.example.entity.StudentsVO;
import com.example.service.MyStudentService;

@RestController
public class MyStudentController {
	@Autowired
	private MyStudentService myStudentService;
	/**
	 * 根据条件查询学生信息
	 * @param studentsVO
	 * @return
	 */
	@PostMapping("/findMyStudentAll")
	public Map<String, Object> findMyStudentAll(StudentsVO studentsVO) {

		// 设置mysql分页用的偏移量offset
		studentsVO.setOffset((studentsVO.getPage() - 1) * studentsVO.getLimit());
		// 查询条数
		int count = myStudentService.getCountStudents(studentsVO);
		// 调用查询
		List<Students> list = myStudentService.findMyStudentAll(studentsVO);
		// 返回结果
		Map<String, Object> rslMap = new HashMap<String, Object>();
		rslMap.put("code", "0");
		rslMap.put("msg", "success");
		rslMap.put("count", count);
		rslMap.put("data", list);
		return rslMap;
	}
	/**
	 * 修改学生信息
	 * @param netFollows
	 * @return
	 */
	@PostMapping("/updateStudent")
	public Map<String, Object> updateStudent(Students students) {
		// 调用新增
		int rows = myStudentService.update(students);
		// 返回结果
		Map<String, Object> rslMap = new HashMap<String, Object>();
		rslMap.put("code", rows > 0 ? "0" : "1");
		rslMap.put("msg", rows > 0 ? "修改成功" : "修改失败");
		return rslMap;
	}
	/**
	 * 根据id删除学生信息
	 * @param id
	 * @return
	 */
	@PostMapping("/delStudent")
	public Map<String, Object> delStudent(int id) {
		// 调用新增
		int rows = myStudentService.delStudent(id);
		// 返回结果
		Map<String, Object> rslMap = new HashMap<String, Object>();
		rslMap.put("code", rows > 0 ? "0" : "1");
		rslMap.put("msg", rows > 0 ? "删除成功" : "删除失败");
		return rslMap;
	}
	
	/**
	 * 添加跟踪信息
	 * @param netFollows
	 * @return
	 */
	@PostMapping("/addnetfollows")
	public Map<String, Object> addnetfollows(Netfollows netFollows){
		// 调用新增
		int rows = myStudentService.addnetfollows(netFollows);
		// 返回结果
		Map<String, Object> rslMap = new HashMap<String, Object>();
		rslMap.put("code", rows > 0 ? "0" : "1");
		rslMap.put("msg", rows > 0 ? "添加成功" : "添加失败");
		return rslMap;
	}
}
